package com.dehui.traders.adapter;

import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

import com.dehui.traders.R;
import com.dehui.traders.bean.OptionalStockBean;
import com.dehui.traders.utils.BaseRecyclerAdapter;
import com.dehui.traders.utils.SmartViewHolder;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView;

import java.util.Collection;

/**
 * Created by hqq on 18.4.19.
 */

public class OptionalStockManagerAdapter extends BaseRecyclerAdapter<OptionalStockBean>{

    private SwipeMenuRecyclerView recyclerView;

    public OptionalStockManagerAdapter(Collection<OptionalStockBean> collection, int layoutId, SwipeMenuRecyclerView recyclerView) {
        super(collection, layoutId);
        this.recyclerView = recyclerView;
    }

    @Override
    protected void onBindViewHolder(SmartViewHolder holder, OptionalStockBean model, int position) {
        TextView tvTitle = holder.findViewById(R.id.tv_title);
        TextView tvCode = holder.findViewById(R.id.tv_code);
        tvTitle.setText(model.name);
        tvCode.setText(model.code);
        holder.findViewById(R.id.iv_drag).setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int action = event.getAction();
                switch (action){
                    case MotionEvent.ACTION_DOWN:
                        recyclerView.startDrag(holder);
                        break;
                }
                return false;
            }
        });

    }


}
